
//chat消息
module.exports = (sequelize, Sequelize) => {
  return sequelize.define("ChatMessage", {
    id: {
      type: Sequelize.UUID,
      notNull: true,
      primaryKey: true,
      defaultValue: Sequelize.UUIDV4 // 或 DataTypes.UUIDV1
    },
    sender: {
      type: Sequelize.STRING,
      allowNull: false,
      comment: "发送者ID",
    },
    receiver: {
      type: Sequelize.STRING,
      allowNull: false,
      comment: "接收者ID 或 群组ID",
    },
    type: {
      type: Sequelize.ENUM("private", "group"),
      allowNull: false,
      comment: "消息类型（private: 私聊, group: 群聊）",
    },
    senderHead: {
      type: Sequelize.STRING,
      allowNull: false,
      comment: "用户头像",
    },
    message: {
      type: Sequelize.TEXT,
      allowNull: false,
      comment: "消息内容",
    },
    timestamp: {
      type: Sequelize.DATE,
      defaultValue: Sequelize.NOW,
      comment: "发送时间",
    }
  }, {
    tableName: "mg_chat_message", // ✅ **数据库表名 `chat_message`**
    // timestamps: false, // ✅ **关闭 `createdAt` & `updatedAt`**
  });
};

